﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;

namespace QuanLyShopCD.BL
{
    class cl_caydanhmuc
    {
        AcessData con;
        Form frm;
        String SQL;
        public cl_caydanhmuc(QuanLyShopCD.GUI.frm_caydanhmuc f)
        {
            con = new AcessData();
            this.frm = f;
        }

        //public void hienthicay()
        //{
        //    SQL = "select *from DanhMuc";
        //    con.Open();
        //    DataTable tb_DM = con.Get_DataTable(SQL);
        //    TreeView tv = (TreeView)frm.Controls["trv_danhmuc"];
        //    foreach (DataRow dr in tb_DM.Rows)
        //    {
        //        TreeNode Node_p = new TreeNode();
        //        Node_p.Text = dr["TenDM"].ToString();
        //        Node_p.Tag = dr["MaDM"].ToString();
        //        //tv.Nodes.Add(Node_p);
        //        SQL = "select * from ShopCD where MaDM = '" + dr["MaDM"].ToString() + "'";
        //            DataTable tb_Shopcd = con.Get_DataTable(SQL);
        //            foreach (DataRow row in tb_Shopcd.Rows)
        //            {
        //                TreeNode Node_CH = new TreeNode();
        //                Node_CH.Text = row["TenLoai"].ToString();
        //                Node_CH.Tag = row["MaCD"].ToString();
        //                Node_p.Nodes.Add(Node_CH);
        //            }
        //            tv.Nodes.Add(Node_p);
                    
        //    }

        //}ro

        public void hienthicay()
        {
            SQL = "select * from DanhMuc";
            con.Open();
            DataTable tb_DM = con.Get_DataTable(SQL);
            TreeView tv = (TreeView)frm.Controls["trv_danhmuc"];
            foreach (DataRow dr in tb_DM.Rows)
            {
                TreeNode Node_P = new TreeNode();
                Node_P.Text = dr["TenDM"].ToString();
                Node_P.Tag = dr["MaDM"].ToString();
                SQL = "select * from ShopCD where MaDM = '"+dr["MaDM"].ToString()+"'";
                DataTable tb_shopcd = con.Get_DataTable(SQL);
                    foreach (DataRow row in tb_shopcd.Rows)
                    {
                        TreeNode tr_CH = new TreeNode();
                        tr_CH.Text = row["TenLoai"].ToString();
                        tr_CH.Tag = row["MaCD"].ToString();
                        Node_P.Nodes.Add(tr_CH);
                    }
                    tv.Nodes.Add(Node_P);
            }
        }

        //public void hienthi_View(string MaDM)
        //{
        //    SQL = "select * from ShopCD where MaDM = '" + MaDM + "'";
        //    con.Open();
        //    DataTable tb_Shopcd = con.Get_DataTable(SQL);
        //    ListView lv = (ListView)frm.Controls["lsv_DanhSachCD"];
        //    lv.Items.Clear();
        //    foreach (DataRow row in tb_Shopcd.Rows)
        //    {
        //        ListViewItem it = new ListViewItem();
        //        it.Text = row["TenLoai"].ToString();
        //        ListViewItem.ListViewSubItem it_sub = new ListViewItem.ListViewSubItem();
        //        it_sub.Text = row["MaCD"].ToString();
        //        it.SubItems.Add(it_sub);
        //        lv.Items.Add(it);

        //    }
        //}

        public void hienthi_View(string MaDM)
        {
            SQL = "select * from ShopCD where MaDM = '" + MaDM + "'";
            con.Open();
            ListView lv = (ListView)frm.Controls["lsv_DanhSachCD"];
            DataTable tb = con.Get_DataTable(SQL);
            lv.Items.Clear();
            foreach(DataRow dr in tb.Rows)
            {
                ListViewItem it = new ListViewItem();
                it.Text = dr["TenLoai"].ToString();
                ListViewItem.ListViewSubItem it_sub = new ListViewItem.ListViewSubItem();
                it_sub.Text = dr["MaCD"].ToString();
                it.SubItems.Add(it_sub);
                lv.Items.Add(it);
            }

        }
    }
}
